<?php
// upload data set
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, "http://localhost/wekaws/upload_dataset_service.php");
    curl_setopt($ch, CURLOPT_POST, true);
    $post = array(
        "file"=>"@".$_FILES["file"]["tmp_name"],
        "model_name" => $_POST["model_name"],
        "extension" => end(explode('.', $_FILES["file"]["name"])),
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $upload = curl_exec($ch);
    $upload = json_decode($upload);
    
// preprocess
    $attr = "00000000000000000000000";
    foreach ($_POST["attribute"] as $i) {
        $attr[$i] = '1';
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, "http://localhost/wekaws/preprocess_service.php");
    curl_setopt($ch, CURLOPT_POST, true);
    $post = array(
        "model_name"=>$_POST["model_name"],
        "preprocess"=> $_POST["preprocess"],
        "attr" => $attr,
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $preprocess = curl_exec($ch);
    $preprocess = json_decode($preprocess);
    
// learning        
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, "http://localhost/wekaws/learning_service.php");
    curl_setopt($ch, CURLOPT_POST, true);
    $post = array(
        "model_name"=>$_POST["model_name"],
        "learning"=> $_POST["learning"],
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $learning = curl_exec($ch);
    $learning = json_decode($learning);


?>
<!DOCTYPE html>
<html>
    <head>
        <title>Mushroom Clasification</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<LINK href="Style.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div class="title">
			Classify Your Mushroom Before Eat!
		</div>
		<hr>
                <button onclick="javascript:window.location='Learning.php'" value="Learning"> Learn New Model </button>
                <button onclick="javascript:window.location='Classification.php'" value="Classification"> Classify </button>
                <button onclick="javascript:window.location='download.php'" value="Allmodel"> List All Model </button>
		<div class="content">
			
			<div style="margin-left:20px">
                            <?php
                                if ($learning->status != "fail" && $upload->status != "fail" && $preprocess->status != "fail"){
                            ?>
                                <h3>
                                    Learning success!!
                                </h3>
                                <h3>Download your file ! </h3> <a href='<?php echo $learning->link?>'>link model</a>
                            <?
                                } else {
                            ?>
                                <h3>
                                    Learning failed!!
                                </h3>
                            <?        
                                }
                            ?>
			</div>
		</div>
    </body>
</html>
